using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Sublimation
{
    public class Sublimation : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;

        //TODO: spritebatch as a game service or something

        protected WorldProperties worldProperties;
        public WorldProperties WorldProperties
        {
            get { return this.worldProperties; }
        }

        // inputs
        GamePadState previousGamePadState = GamePad.GetState(PlayerIndex.One);
#if !XBOX
        KeyboardState previousKeyboardState = Keyboard.GetState();
        const int keyboardScrollSpeed = 10;
#endif

        public Sublimation()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            this.graphics.PreferredBackBufferWidth = 1024;
            this.graphics.PreferredBackBufferHeight = 768;
            this.graphics.IsFullScreen = false;
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();

            // Create a new SpriteBatch, which can be used to draw textures.
            // spriteBatch = new SpriteBatch(GraphicsDevice);

            worldProperties = new WorldProperties(this);
            worldProperties.Map = new GameMap(this, "ForrestMap");

            // get the game set up - this could move to allow selection of races etc if necessary
            WorldProperties.PlayerCount = 1;

            WorldProperties.StartGame();
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // handle any input 
            HandleInput();

            base.Update(gameTime);
        }

        protected void HandleInput()
        {
            // load states and allow exit
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
            if (gamePadState.Buttons.Back == ButtonState.Pressed) this.Exit();
#if !XBOX
            KeyboardState keyboardState = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.Escape)) this.Exit();
#endif

            // save previous states
            previousGamePadState = gamePadState;
#if !XBOX
            previousKeyboardState = keyboardState;
#endif
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            //spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            //spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
